package com.ymatou.iapi.login.service;

import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.common.entitie.UserData;
import com.ymttest.utils.EnvSetup;

/**
 * 登入认证Call FreeMaker Template自动生成代码
 */
public class LoginAuthCall extends YmatouBaseCall {
	private static String opurl = "json/reply/LoginAuthRequestDto";

	public LoginAuthCall() {
		super(EnvSetup.getSystemUrl("login_iapi"), opurl, "GET", "PARAM");
	}
	
	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取是否成功
	 * 
	 * @return Boolean
	 */
	public Boolean getSuccess() {
		Boolean Success = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Success = jo.getBoolean("Success");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Success;
	}
	
	/**
	 * 获取ResponseCode
	 * 
	 * @return Boolean
	 */
	public Integer getResponseCode() {
		Integer Success = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Success = jo.getInt("ResponseCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Success;
	}
	
	/**
	 * 获取LastErrorMessage
	 * 
	 * @return Boolean
	 */
	public String getLastErrorMessage() {
		String Success = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Success = jo.getString("LastErrorMessage");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Success;
	}
	
	/**
	 * 获取是否成功
	 * 
	 * @return Boolean
	 */
	public Integer getErrorCode() {
		Integer Success = null ;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Success = jo.getInt("ErrorCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Success;
	}

	/**
	 * 获取UserData
	 * 
	 * @return UserData
	 */
	public UserData getUserData() {
		UserData udata = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			udata = (UserData) FormatUtil
					.GSONToObject(jo.getJSONObject("Result").getString("UserData"), UserData.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return udata;
	}
	
	/**
	 * 获取msg
	 * 
	 * @return msg
	 */
	public String getMsg() {
		String msg = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			msg = jo.getString("LastErrorMessage");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return msg;
	}
	
	public String getLoginRiskCode() {
		String Success = null;
		try {
			JSONObject jo = new JSONObject(getString("Result"));
			Success = jo.getString("LoginRiskCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Success;
	}
}